﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ppt_to_png
{
    public partial class UserControl1 : UserControl
    {
        private const string FilePathHead = "head.txt";
        private const string FilePathTail = "tail.txt";
        private const string FilePathClass = "class.txt";
        private const string FilePathItem = "item.txt";

        public UserControl1()
        {
            InitializeComponent();
            LoadData();
        }

        private void LoadData()
        {
            try
            {
                if (File.Exists(FilePathHead))
                {
                    using (StreamReader sr = new StreamReader(FilePathHead))
                    {
                        richTextBox_头.Text = sr.ReadToEnd();
                    }
                }

                if (File.Exists(FilePathTail))
                {
                    using (StreamReader sr = new StreamReader(FilePathTail))
                    {
                        richTextBox_尾.Text = sr.ReadToEnd();
                    }
                }

                if (File.Exists(FilePathClass))
                {
                    using (StreamReader sr = new StreamReader(FilePathClass))
                    {
                        richTextBox_类.Text = sr.ReadToEnd();
                    }
                }

                if (File.Exists(FilePathItem))
                {
                    using (StreamReader sr = new StreamReader(FilePathItem))
                    {
                        richTextBox_项.Text = sr.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error loading content: {ex.Message}");
            }
        }

        public void SaveData()
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(FilePathHead))
                {
                    sw.Write(richTextBox_头.Text);
                }

                using (StreamWriter sw = new StreamWriter(FilePathTail))
                {
                    sw.Write(richTextBox_尾.Text);
                }

                using (StreamWriter sw = new StreamWriter(FilePathClass))
                {
                    sw.Write(richTextBox_类.Text);
                }

                using (StreamWriter sw = new StreamWriter(FilePathItem))
                {
                    sw.Write(richTextBox_项.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error saving content: {ex.Message}");
            }
        }

      
    }
}
